package jsu.yym.tiktok.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import jsu.yym.tiktok.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {
    //根据username查找用户
    @Select("select * from user where username = #{username}")
    User getUserByUserName(String username);

    @Select("select * from user where email = #{email}")
    User getUserByEmail(String email);

    @Select("select * from user where nickname = #{nickname}")
    List<User> getUserByNickName(String nickname);

    @Select("select * from user where address = #{address} and state = #{state}")
    List<User> getUserByAddressAndState(String address,int state);

//    @Select("select * from user where state = #{state}")
//    List<User> getUserByState(int state);

    @Select("select address from user where username = #{username}")
    String getAddressByUserName(String username);

    @Select("select targe from user where username = #{username}")
    String getTargeByUserName(String username);

    @Select("select image from user where username = #{username}")
    String getImageByUserName(String username);

    @Select("select file_name from user where username = #{username}")
    String getFileNameByUserName(String username);


    @Update("UPDATE user SET password = #{password} WHERE email = #{email}")
    int updateUserByEmail(@Param("password")String password,@Param("email") String email);

    @Update("UPDATE user SET targe = #{targe} WHERE username = #{username}")
    int updateTargeByUsername(@Param("targe")String targe,@Param("username") String username);

    @Update("UPDATE user SET image = #{image}, file_name = #{fileName} WHERE username = #{username}")
    int updateImgAndFileNameByUsername(@Param("image") String image, @Param("fileName") String fileName, @Param("username") String username);




    @Select({
            "<script>",
            "SELECT * FROM user",
            "WHERE username IN",
            "<foreach item='id' collection='IdList' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "</script>"
    })
    List<User> getUsersByUsernames(@org.springframework.data.repository.query.Param("IdList") List<String> IdList);

}
